import request from "@/utils/request";
const baseUrlV2 = '/api'
const defaultApi = (apiName) => {
    return {
        tree: (params) => request.get(`/${apiName}/tree`, { params }),
        list: (params) => request.get(`/${apiName}/list`, { params }),
        page: (params) => request.get(`/${apiName}`, { params }),
        read: (id) => request.get(`/${apiName}/` + id),
        create: (id, data) => request.post(`/${apiName}`, data),
        update: (id, data) => request.put(`/${apiName}/` + id, { ...data, create_time: undefined, id: undefined }),
        delete: (id) => request.delete(`/${apiName}/` + id)
    }
}
export const http = {
    menu: {
        ...defaultApi('system/menu'),
        page: undefined,
        list: (params) => request.get(`/system/menu/tree`, { params }),
    },
    role: {
        ...defaultApi('system/role'),
        roleList: () => request.get('/system/role/simple-list'),
        getRoleMenus: (roleId) => request.get('/system/permission/list-role-menus?roleId=' + roleId),
        updateRoleMenus: (data) => request.post('/system/permission/assign-role-menu', data)
    },
    systemUser: {
        ...defaultApi('system/user'),
        getUserRoles: (userId) => request.get('/system/permission/list-user-roles?userId=' + userId),
        updateUserRoles: (data) => request.post('/system/permission/assign-user-role', data)
    },
    login: (data) => request.post('/system/auth/login', data),
    getUserInfo: () => request.get('/system/auth/get-permission-info'),

    config: {
        ...defaultApi('config')
    },
    affordableHousing: {
        ...defaultApi('affordable-housing')
    },
    jobSubsidy: {
        ...defaultApi('job-subsidy')
    },
    startupSubsidy: {
        ...defaultApi('startup-subsidy')
    },
    housingPurchaseSubsidy: {
        ...defaultApi('housing-purchase-subsidy')
    },
    employmentSubsidy: {
        ...defaultApi('employment-subsidy')
    },
    settlementSubsidy: {
        ...defaultApi('settlement-subsidy')
    },
    youthHostel: {
        ...defaultApi('youth-hostel')
    },
    point: {
        ...defaultApi('point')
    }
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
